package com.msi.gui;

import java.awt.BorderLayout;

import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;

import com.msi.Graph;
import com.msi.visualization.GraphVisualization;

public class GUIAdapter {

	private static final int WINDOW_HEIGHT = 660;
	private static final int WINDOW_WIDTH = 650;
	public JTextArea output;
	public JScrollPane scrollPane;
	private JMenuBar menuBar;
	private JPanel container;
	private GraphVisualization graphV;

	MenuAdapter menu = new MenuAdapter();

	public GUIAdapter() {
		super();
		container = createContentPane();
		menuBar = menu.createMenuBar(container);
	}

	public void createAndShowGUI() {
		// Create and set up the window.
		JFrame frame = new JFrame("MSI");
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

		frame.setJMenuBar(menuBar);
		frame.setContentPane(container);

		graphV = GraphVisualization.createGraphVisualization();
		frame.getContentPane().add(graphV);

		// Display the window.
		frame.setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
		frame.setVisible(true);
	}

	public void visualizeGraph(Graph graph) {
		graphV.buildGraph(graph);
	}

	private JPanel createContentPane() {

		// Create the content-pane-to-be.
		JPanel contentPane = new JPanel(new BorderLayout());
		contentPane.setOpaque(true);

		// Create a scrolled text area.
		output = new JTextArea(5, 30);
		output.setEditable(false);
		scrollPane = new JScrollPane(output);

		return contentPane;
	}

	/** Returns an ImageIcon, or null if the path was invalid. */
	protected static ImageIcon createImageIcon(String path) {
		return null;
	}
}
